# leet-code(20) 有效的括号

def is_valid(s: str) -> bool:
    if not bool(s) or len(s) < 2:
        return False
    stack = []
    for cur in s:
        if cur == '(':
            stack.append(')')
        elif cur == '[':
            stack.append(']')
        elif cur == '{':
            stack.append('}')
        else:
            if len(stack) == 0:
                return False
            if stack.pop() != cur:
                return False

    return len(stack) == 0


if __name__ == '__main__':
    print(is_valid('()'))
    print(is_valid('()[]{}'))
    print(is_valid('(]'))
